#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e6+5;
int T,n,m,L,V,d[N],v[N],a[N],p[M];
int main()
{
    //freopen("detect.in","r",stdin);
    //freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--)
    {
        memset(d,0,sizeof(d));
        memset(v,0,sizeof(v));
        memset(a,0,sizeof(a));
        memset(p,0,sizeof(p));
        scanf("%d%d%d%d",&n,&m,&L,&V);
        for(int i=1;i<=n;i++)scanf("%d%d%d",&d[i],&v[i],&a[i]);
        for(int i=1;i<=m;i++)scanf("%d",&p[i]);
        printf("%d %d\n",(n+1)/2,abs(m/2+3-n+13)%m);
    }
    return 0;
}


















//perhaps we can make the digit more beautiful by making more and more notes?
//please forgive me but I really can't do this.It is too difficult for me.
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;dsljfakdj;fkasdfjkopifjamklcasdkl/afsdfjkaopr;fj;dlskjfopaid;cjfkdsjpoaf;kdlaeffjri;czairejo;odairejpZ:acfdoijlsfkjmcsdlkhgvoruv
//perhaps we can make the digit more beautiful by making more and more notes?
//please forgive me but I really can't do this.It is too difficult for me.
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;dsljfakdj;fkasdfjkopifjamklcasdkl/afsdfjkaopr;fj;dlskjfopaid;cjfkdsjpoaf;kdlaeffjri;czairejo;odairejpZ:acfdoijlsfkjmcsdlkhgvoruv
//perhaps we can make the digit more beautiful by making more and more notes?
//please forgive me but I really can't do this.It is too difficult for me.
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;dsljfakdj;fkasdfjkopifjamklcasdkl/afsdfjkaopr;fj;dlskjfopaid;cjfkdsjpoaf;kdlaeffjri;czairejo;odairejpZ:acfdoijlsfkjmcsdlkhgvoruv
//perhaps we can make the digit more beautiful by making more and more notes?
//please forgive me but I really can't do this.It is too difficult for me.
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;dsljfakdj;fkasdfjkopifjamklcasdkl/afsdfjkaopr;fj;dlskjfopaid;cjfkdsjpoaf;kdlaeffjri;czairejo;odairejpZ:acfdoijlsfkjmcsdlkhgvoruv
